package it.polimi.TravelDream.ejb.entities;

import it.polimi.TravelDream.ejb.dtos.RoomDTO;
import it.polimi.TravelDream.ejb.entities.Hotel;

import java.io.Serializable;
import java.util.List;

import javax.persistence.*;

/**
 * Entity implementation class for Entity: RoomEAO
 *
 */
@Entity
@Table(name="rooms")
@NamedQueries({

    @NamedQuery(name = Room .FIND_ROOM_BY_CITY, query ="SELECT r FROM Room r WHERE r.hotelName.hotelAddress.city = :city ORDER BY r.hotelName.name ASC"),
    @NamedQuery(name = Room .FIND_ROOM_BY_HOTEL_AND_BEDS, query ="SELECT r FROM Room r WHERE r.hotelName = :hotelName and r.beds= :beds"),
    @NamedQuery(name = Room .FIND_ALL, query="Select r FROM Room r"),
    @NamedQuery(name = Room .FIND_DISTINCT_HOTEL, query="SELECT DISTINCT r.hotelName FROM Room r"),
    @NamedQuery(name = Room.FIND_ROOM_BY_CITY_AND_NATION, query ="SELECT r FROM Room r WHERE r.hotelName.hotelAddress.city = :city and r.hotelName.hotelAddress.nation=:nation"),
    @NamedQuery(name = Room.FIND_ALL_ROOMS, query = "SELECT r FROM Room r")
})

public class Room implements Serializable {

	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private int roomID;
	private int roomNumber;
	private int beds;
	private double price;
	private boolean available = true; 

	//Pacchetti utente in cui sono contenute le camere
	@ManyToMany(mappedBy = "rooms")
	private List <UserPackage> list_of_userpackage;
	
	//Pacchetti in cui sono contenute le camere
	@ManyToMany(mappedBy = "rooms")
	private List <BasicPackage> list_of_package;

	//Nome dell'hotel a cui la camera appartiene
	@ManyToOne(optional = false)
	@JoinColumn(name = "hotels_hotelID", referencedColumnName = "hotelID")
	private Hotel hotelName;
	
	private static final long serialVersionUID = 1L;
	public static final String FIND_ROOM_BY_CITY = "Room.findRoomByCity";	
	public static final String FIND_ROOM_BY_HOTEL_AND_BEDS = "Room.findRoomByPackageHotelAndBeds";
	public static final String FIND_ALL = "Room.findAll";
	public static final String FIND_DISTINCT_HOTEL="Room.findDistinctHotel";
	public static final String FIND_ROOM_BY_CITY_AND_NATION = "Room.findRoomByCityAndNation";
	public static final String FIND_ALL_ROOMS = "Room.findAllRooms";

	public Room() {
		super();
		this.available = true;
	}   
	
	public Room(RoomDTO roomDTO) {
		super();
		this.roomNumber = roomDTO.getRoomNumber();
		this.beds = roomDTO.getBeds();
		this.price = roomDTO.getPrice();
		this.available = roomDTO.isAvailable();
	}
	
	public int getRoomID() {
		return this.roomID;
	}

	public void setRoomID(int roomID) {
		this.roomID = roomID;
	}   
	public int getRoomNumber() {
		return this.roomNumber;
	}

	public void setRoomNumber(int roomNumber) {
		this.roomNumber = roomNumber;
	}   
	public int getBeds() {
		return this.beds;
	}

	public void setBeds(int beds) {
		this.beds = beds;
	}   
	public double getPrice() {
		return this.price;
	}

	public void setPrice(double price) {
		this.price = price;
	}   
	public boolean getAvailable() {
		return this.available;
	}

	public void setAvailable(boolean available) {
		this.available = available;
	}   
	public Hotel getHotelName() {
		return this.hotelName;
	}

	public void setHotelName(Hotel hotelName) {
		this.hotelName = hotelName;
	}
	public List<UserPackage> getList_of_userpackage() {
		return list_of_userpackage;
	}

	public void setList_of_userpackage(List<UserPackage> list_of_userpackage) {
		this.list_of_userpackage = list_of_userpackage;
	}

	public List<BasicPackage> getList_of_package() {
		return list_of_package;
	}

	public void setList_of_package(List<BasicPackage> list_of_package) {
		this.list_of_package = list_of_package;
	}
   
}
